/*
 * HttpHost.h
 *
 */

#ifndef HTTPHOST_H_
#define HTTPHOST_H_

#include "../Process.h"

class HttpBody;
class HttpRequest;
class HttpResponse;
class HttpGet;
class HttpPost;
class LogFile;
class ServerConfig;

class HostException : public std::exception {
	private:
		std::string msg;
	public:
		explicit HostException(const std::string& msg) throw();
		virtual ~HostException() throw() {}
		const char* what() const throw() { return msg.c_str(); }
};

class HttpHost {
	private:
		static const int DATA_BUFFER_SIZE = 512;
		const ServerConfig& config;
		LogFile& logFile;
		Process process;

	protected:
		bool staticProcess(HttpResponse& response, const HttpRequest& request);
		bool dynamicProcess(HttpResponse& response, const HttpRequest& request);
		bool authenticated(HttpResponse& response, const HttpRequest& request);

		std::string resourcePath(const std::string& resource) const;
		std::string resourceExtension(const std::string& resource) const;
		void openOrCreate(std::ofstream& file, const std::string& filename);
	public:
		HttpHost(const ServerConfig& config, LogFile& logFile);
		virtual ~HttpHost();

		void errorProcess(HttpResponse& response, int code);
		void generateResponse(HttpResponse& response,
				const HttpRequest& message);
		void terminate();

		static const std::string VERSION;
};

#endif /* HTTPHOST_H_ */
